<?php
function betin3a( $lotto_id, $bettype, $nums, $rate1, $rate, $money, $betcounts, $backs, $account )
{
    $betmoney = $money * $betcounts;
    $fields = array();
    $fields['lotto_id'] = $lotto_id;
    $fields['createtime'] = systime();
    $fields['bettype'] = $bettype;
    $fields['numbers'] = "'{$money}|{$rate}|{$betcounts}|{$nums}'";
    $fields['line_nums'] = "'{$nums}'";
    $fields['amount'] = $betmoney;
    $fields['rate'] = $rate1;
    $fields['back'] = $backs;
    $fields['account'] = "'".$account."'";
    db_insert( "bet8", $fields );
}

echo "  ";
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$lotto_id = intval( $_POST['lotto_id'] );
$bettype = intval( $_POST['type'] );
if ( $bettype == 29 )
{
    $count_num = 5;
}
else
{
    $count_num = $bettype == 8 || $bettype == 9 || $bettype == 33 ? 3 : 2;
}
$num = array();
$numcount = 0;
$i = 1;
while ( $i < 50 )
{
    if ( isset( $_POST["num_".$i] ) )
    {
        $num[$numcount] = d2( $i );
        ++$numcount;
    }
    ++$i;
}
$rate1 = $_POST['b21a'] + 0;
$rate2 = $_POST['b21b'] + 0;
$backs = $_POST['b22'] + 0;
$money = intval( $_POST['b23'] );
$account = $_POST['account'];
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
if ( 0 < $rate2 )
{
    $rate = $rate1.",".$rate2;
}
else
{
    $rate = $rate1;
}
if ( $count_num == 5 )
{
    $i = 0;
    while ( $i < $numcount - 4 )
    {
        $j = $i + 1;
        while ( $j < $numcount - 3 )
        {
            $k = $j + 1;
            while ( $k < $numcount - 2 )
            {
                $l = $k + 1;
                while ( $l < $numcount - 1 )
                {
                    $m = $l + 1;
                    while ( $m < $numcount )
                    {
                        $nums = explode( ",", $num[$i].",".$num[$j].",".$num[$k].",".$num[$l].",".$num[$m] );
                        sort( $nums );
                        betin3a( $lotto_id, $bettype, implode( ",", $nums ), $rate1, $rate, $money, 1, $backs, $account );
                        ++$m;
                    }
                    ++$l;
                }
                ++$k;
            }
            ++$j;
        }
        ++$i;
    }
}
if ( $count_num == 2 )
{
    $i = 0;
    while ( $i <= $numcount - 2 )
    {
        $j = $i + 1;
        while ( $j < $numcount )
        {
            $nums = explode( ",", $num[$i].",".$num[$j] );
            sort( $nums );
            betin3a( $lotto_id, $bettype, implode( ",", $nums ), $rate1, $rate, $money, 1, $backs, $account );
            ++$j;
        }
        ++$i;
    }
}
$i = 0;
while ( $i <= $numcount - 2 )
{
    $j = $i + 1;
    while ( $j <= $numcount - 2 )
    {
        $k = $j + 1;
        while ( $k < $numcount )
        {
            $nums = explode( ",", $num[$i].",".$num[$j].",".$num[$k] );
            sort( $nums );
            betin3a( $lotto_id, $bettype, implode( ",", $nums ), $rate1, $rate, $money, 1, $backs, $account );
            ++$k;
        }
        ++$j;
    }
    ++$i;
}
echo "<p>走飞成功！</p>";
echo "<p><input type=button value='回上一页' onclick='history.back()'></p>";
echo "<script>";
echo "setTimeout(\"location.href='op.php?op=admin&fp=unow3&select={$selectid}'\",30000);";
echo "</script>";
?>